import 'dart:developer';

import 'package:flutter/material.dart';
// import 'package:flutter_tts/flutter_tts.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:translator/translator.dart';

import 'LanguageList.dart';


class LanguagePage extends StatefulWidget {
  int type;
  String aim;
  LanguagePage(this.aim,this.type);
  @override
  _LanguagePageState createState() => _LanguagePageState();
}

class _LanguagePageState extends State<LanguagePage> {
  GoogleTranslator translator = GoogleTranslator();
  List<dynamic> languages = [];
  List<dynamic> histories = [];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    initData();
  }
  initData()async{
    // languages = LanguageList.getList().map((key, value) => value);
    LanguageList.getList().forEach((key, value) {
      languages.add("$value");
    });
    if(widget.type==1) {
      languages.removeAt(0);
    }
    setState(() {
    
    });
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        brightness: Brightness.light,
        automaticallyImplyLeading: false,
        elevation: 0,
        backgroundColor: Colors.transparent,
        title: Text("Select Language",style: TextStyle(fontWeight: FontWeight.w500,color: Color(0xff4474fb)),),
        actions: [
          IconButton(icon: Icon(Icons.close_rounded,color: Color(0xff4474fb),), onPressed: ()=>Navigator.pop(context))
        ],
      ),
      body: Container(
        padding: EdgeInsets.symmetric(horizontal: 16),
        child: Column(
          children: [
            Expanded(child: ListView.builder(
              physics: BouncingScrollPhysics(),
              itemBuilder: (context,index)=>ListTile(
                selectedTileColor: Color(0xff4474fb),
                selected: widget.aim==languages[index],
                onTap: ()async{
                  Navigator.pop(context,languages[index]);
                },
                title: Text("${languages[index]}",style: TextStyle(color:widget.aim==languages[index]?Colors.white:Colors.black ),),
              ),itemCount: languages.length,
            )
            )
          ],
        ),
      ),
    );
  }

}

